package com.example;

import org.junit.Test;

import java.io.*;

public class IOTest02 {

    @Test
    public void test01() throws IOException {
        // 相当于InputStream，以字节为单位处理数据
        // Reader、Writer以字符为单位处理数据
        Reader reader = new
                FileReader("F:/课堂/Java面向对象编程基础/data/login.html");
        // 相当于OutputStream
        Writer writer = new
                FileWriter("F:/课堂/Java面向对象编程基础/data/login-副本.html");
        char[] buffer = new char[1024];
        int length;
        while ((length = reader.read(buffer)) != -1) {
            //System.out.println(new String(buffer, 0, length));
            writer.write(buffer, 0, length);
        }
        // 字符的数组构建成字符串
        writer.close();
        reader.close();
    }

    @Test
    public void test02() throws IOException {
        Reader reader = new
                FileReader("F:/课堂/Java面向对象编程基础/data/login.html");
        BufferedReader br = new BufferedReader(reader);
        Writer writer = new
                FileWriter("F:/课堂/Java面向对象编程基础/data/login-副本.html");
        BufferedWriter bw = new BufferedWriter(writer);
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
            bw.write(line);
        }
        bw.close();
        writer.close();
        br.close();
        reader.close();
    }
}
